הנכות 1 תואיגש םע תודדומתהו תואלול,םיכרעמ : לו 2 גרת

Size: px
Start display at page:

Download "הנכות 1 תואיגש םע תודדומתהו תואלול,םיכרעמ : לו 2 גרת"

Transcription

1 תוכנה 1 תרגול 2: מערכים, לולאות והתמודדות עם שגיאות

2 מערכים Array: A fixed-length data structure for storing multiple values of the same type Example from last week: An array of odd numbers: Indices (start from 0) odds: The type of all elements is int odds.length == 8 The value of the element at index 4 is 9: odds[4] == 9 2

3 Array Variables An array is denoted by the [] notation Examples: int[] odds; String[] names; int[][] matrix; // an array of arrays matrix: 3

4 Array Creation and Initialization What is the output of the following code: int[] odds = new int[8]; for (int i = 0; i < odds.length; i++) { System.out.print(odds[i] + " "); odds[i] = 2 * i + 1; System.out.print(odds[i] + " "); Output: Array creation: all elements get the default value for their type (0 for int)

5 Array Creation and Initialization Creating and initializing small arrays with a-priori known values: int[] odds = {1,3,5,7,9,11,13,15; String[] months = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "July", "Aug", "Sep", "Oct", "Nov", "Dec"; Jan months: 5

6 Loop through Arrays By promoting the array's index: for (int i = 0; i < months.length; i++) { foreach: System.out.println(months[i]); for (String month: months) { System.out.println(month); The variable month is assigned the next element in each iteration 6

7 Operations on arrays The class Arrays provide operations on array Copy Sort Search Fill... java.util.arrays ays.html 7

8 Copying Arrays Assume: int[] array1 = {1,2,3; int[] array2 = {8,7,6,5; Naïve copy: array1 = array2; 8,7,6,5 array2 1,2,3 array1 What s wrong with this solution? 8

9 Copying Arrays Arrays.copyOf 1 st argument: the original array 2 nd argument: the length of the copy int[] arr1 = {1, 2, 3; int[] arr2 = Arrays.copyOf(arr1, arr1.length); Arrays.copyOfRange 1 st argument: the original array 2 nd initial index of the range to be copied, inclusive 3 rd argumrnt: final index of the range to be copied, exclusive 9

10 Question What is the output of the following code: int[] odds = {1, 3, 5, 7, 9, 11, 13, 15; int newodds[] = Arrays.copyOfRange(odds, 1, odds.length); for (int odd: newodds) { System.out.print(odd + " "); Output:

11 2D Arrays There are no 2D arrays in Java but you can build array of arrays: char[][] board = new char[3][]; for (int i = 0; i < 3; i++) board[i] = new char[3]; Or equivalently: char[][] board = new char[3][3]; board 11

12 2D Arrays A more compact table: int[][] table = new int[10][]; for (int i = 0; i < 10; i++) { table[i] = new int[i + 1]; for (int j = 0; j <= i; j++) { table[i][j] = (i + 1) * (j + 1); table 1 12

13 Fibonacci Fibonacci series 1, 1, 2, 3, 5, 8, 13, 21, 34 Definition: fib(0) = 1 fib(1) = 1 fib(n) = fib(n-1) + fib(n-2) en.wikipedia.org/wiki/fibonacci_number

14 If-Else Statement public class Fibonacci { /** Returns the n-th Fibonacci element */ public static int computeelement(int n) { if (n==0) return 1; else if (n==1) return 1; else return computeelement(n-1) + computeelement(n-2); Can be removed Assumption: n 0 14

15 Switch Statement public class Fibonacci { /** Returns the n-th Fibonacci element */ public static int computeelement(int n) { switch(n) { case 0: return 1; case 1: return 1; default: Assumption: n 0 can be placed outside the switch return computeelement(n-1) + computeelement(n-2); 15

16 Switch Statement public class Fibonacci { /** Returns the n-th Fibonacci element */ public static int computeelement(int n) { switch(n) { case 0: return 1; case 1: return 1; break; default: Compilation Error: Unreachable Code Assumption: n 0 return computeelement(n-1) + computeelement(n-2); 16

17 Iterative Fibonacci A loop instead of a recursion static int computeelement(int n) { if (n == 0 n == 1) return 1; int prev = 1; int prevprev = 1; int curr = 2; Assumption: n 0 for (int i = 2 ; i < n ; i++) { curr = prev + prevprev; Must be initialized. prevprev = prev; Why? prev = curr; curr = prev + prevprev; return curr; prevprev prev curr 17

18 נתונים במקום חישוב בתרגום רקורסיה ללולאה אנו משתמשים במשתני עזר לשמירת המצב curr, prev ו- prevprev הלולאה "זוכרת" בתהליך החישוב דיון: יעילות לעומת פשטות. עיקרון ה- KISS את הנקודה שבה אנו נמצאים )keep it simple stupid( 18

19 For Loop Printing the first n elements: public class Fibonacci { public static int computeelement(int n) { It is better to use args[0] public static void main(string[] args) { for(int i = 0 ; i < 10 ; i++) { System.out.println(computeElement(i)); 19

20 מודולריות, שכפול קוד ויעילות יש כאן חוסר יעילות מסוים: לולאת ה- for חוזרת גם ב- main וגם ב-.computeElement לכאורה, במעבר אחד ניתן גם לחשב את האיברים וגם להדפיס אותם כמו כן כדי לחשב איבר בסדרה איננו משתמשים בתוצאות שכבר חישבנו )של איברים קודמים( ומתחילים כל חישוב מתחילתו 20

21 מודולריות, שכפול קוד ויעילות צריכה לעשות דבר אחד בדיוק! והדפסה פוגע במודולריות )מדוע?( מתודה )פונקציה( ערוב של חישוב היזהרו משכפול קוד! קטע קוד דומה המופיע בשתי פונקציות שונות יגרום במוקדם או במאוחר לבאג בתוכנית )מדוע?( את בעיית היעילות )הוספת מנגנון )memoization אפשר לפתור בעזרת מערכים )תרגיל( 21

22 for vs. while The following two statements are almost equivalent: Variable i is not defined outside the for block for(int i = 0 ; i < n ; i++) System.out.println(computeElement(i)); int i=0; while (i < n) { System.out.println(computeElement(i)); i++; 22

23 while vs. do while The following two statements are equivalent if and only if n>0 : int i=0; while (i < n) { System.out.println(computeElement(i)); i++; int i=0; do { System.out.println(computeElement(i)); i++; while (i>n(; 23

24 Compilation vs. Runtime Errors שגיאות קומפילציה )הידור(: שגיאות שניתן "לתפוס" קריאת הקובץ והפיכתו ל- bytecode ע"י המהדר בעת Syntax error on token "Class", class expected Class MyClass { void f() { int n=10; void g() { int m = 20; int i; System.out.println(i); דוגמאות: Syntax error, insert "" to complete MethodBody בדרך כלל קשורות ל: תחביר, תאימות טיפוסים, הגדרה לפני שימוש 24

25 Compilation vs. Runtime Errors שגיאות זמן ריצה: לא ניתן לדעת שתהיה שגיאה במקום ספציפי בזמן ההידור )קומפילציה( a = new int[20]; int a[] = new int[10]; a[15] = 10; דוגמאות: String s = null; System.out.println(s.length()); מתקשר למנגנון החריגים,)exceptions( עליו נלמד בהמשך 25

26 Compilation vs. Runtime Errors האם יש עוד סוג של טעויות? כן, הכי גרועות, טעויות לוגיות בתוכנית public class Factorial { /** calculate x! **/ public static int factorial(int x) { int f = 0; for (int i = 2; i <= x; i++) f = f * i; return f; 26

27 The Debugger Some programs may compile correctly, yet not produce the desirable results These programs are valid and correct Java programs, yet not the programs we meant to write! The debugger can be used to follow the program step by step and may help detecting bugs in an already compiled program

28 Debugger Add Breakpoint Right click on the desired line Toggle Breakpoint

29 Debugger Start Debugging debug (F11) breakpoint

30 Debugger Debug Perspective

31 Debugger Debugging Current state Back to Java perspective Current location

32 Debugger Debugging

33 Using the Debugger: Video Tutorial מצגות וידאו מדריך עדכני יותר e.html הקישורים נמצאים גם באתר הקורס 33

34 הסוף...

הנכות 1 תואיגש םע תודדומתהו תואלול,םי : כרעמ 2 לוגרת

הנכות 1 תואיגש םע תודדומתהו תואלול,םי : כרעמ 2 לוגרת תוכנה 1 תרגול 2: מערכים, לולאות והתמודדות עם שגיאות מערכים מערכים Array: A fixed-length data structure for storing multiple values of the same type Example from last week: An array of odd numbers: Indices

More information

תוכנה 1 תרגול 2: מערכים ומבני בקרה

תוכנה 1 תרגול 2: מערכים ומבני בקרה תוכנה 1 תרגול 2: מערכים ומבני בקרה 2 Useful Eclipse Shortcuts Ctrl+1 quick fix for errors, or small refactoring suggestions Ctrl+SPACE code content assist (auto-completion) Auto completion for main create

More information

תוכנה 1 מערכים. Array Creation and Initialization. Array Declaration. Loop through Arrays. Array Creation and Initialization

תוכנה 1 מערכים. Array Creation and Initialization. Array Declaration. Loop through Arrays. Array Creation and Initialization מערכים תוכנה 1 Array: A fixed-length data structure for storing multiple values of the same type Example from last week: An array of odd numbers: Indices (start from 0) 0 1 2 3 4 5 6 7 תרגול 2: מערכים

More information

תוכנה 1 3 תרגול מס' מערכים ומבני בקרה

תוכנה 1 3 תרגול מס' מערכים ומבני בקרה תוכנה 1 3 תרגול מס' מערכים ומבני בקרה מערכים Array: A fixed-length data structure for storing multiple values of the same type Example: An array of odd numbers: Indices (start from 0) 0 1 2 3 4 5 6 7 odds:

More information

תוכנה 1 מערכים. Array Creation and Initialization. Array Declaration. Array Creation and Initialization. Loop through Arrays

תוכנה 1 מערכים. Array Creation and Initialization. Array Declaration. Array Creation and Initialization. Loop through Arrays מערכים Array: A fixed-length data structure for storing multiple values of the same type תוכנה 1 Example: An array of odd numbers: Indices (start from 0) 0 1 2 3 4 5 6 7 odds: 1 3 5 7 9 11 13 15 odds.length

More information

תוכנה 1 תרגול 2: מערכים, מבני בקרה ושגיאות

תוכנה 1 תרגול 2: מערכים, מבני בקרה ושגיאות תוכנה 1 תרגול 2: מערכים, מבני בקרה ושגיאות מערכים Array: A fixed-length data structure for storing multiple values of the same type Example: An array of odd numbers: Indices (start from 0) 0 1 2 3 4 5

More information

תוכנה 1 טיפוסי השפה טיפוסים לא פרימיטיביים הטיפוסים הפרימיטיביים מחרוזות המרה למספרים תרגול 2: טיפוסי שפה, מחרוזות, מערכים ושגיאות

תוכנה 1 טיפוסי השפה טיפוסים לא פרימיטיביים הטיפוסים הפרימיטיביים מחרוזות המרה למספרים תרגול 2: טיפוסי שפה, מחרוזות, מערכים ושגיאות טיפוסי השפה תוכנה 1 תרגול 2: טיפוסי שפה, מחרוזות, מערכים ושגיאות טיפוסים יסודיים (פרימיטיביים): 8 טיפוסים מוגדרים בשפה שמיועדים להכיל ערכים פשוטים: מספרים שלמים: byte, short, int, long מספרים ממשיים: float,

More information

Ohad Barzilay and Oranit Dror

Ohad Barzilay and Oranit Dror The String Class Represents a character string (e.g. "Hi") Implicit constructor: String quote = "Hello World"; string literal All string literals are String instances Object has a tostring() method More

More information

Sun שיטת הגמל: "isodd" "is_odd" Sun. תוכנה 1 בשפת Java אוניברסיטת תל אביב

Sun שיטת הגמל: isodd is_odd Sun. תוכנה 1 בשפת Java אוניברסיטת תל אביב Java 1 2 http://java.sun.com/docs/codeconv (24 pages) Sun "isodd" "is_odd" שיטת הגמל: Sun 3 Indentation if (condition) if (condition) { { statements; statements; Sun C 4 Window->preferences->java->code

More information

תוכנה 1 סמסטר א' תשע"א

תוכנה 1 סמסטר א' תשעא General Tips on Programming תוכנה 1 סמסטר א' תשע"א תרגול מס' 6 מנשקים, דיאגרמות וביטים * רובי בוים ומתי שמרת Write your code modularly top-down approach Compile + test functionality on the fly Start with

More information

הנכות 1 םוכיס לוגרת 14 1

הנכות 1 םוכיס לוגרת 14 1 תוכנה 1 סיכום תרגול 14 1 קצת על מנשקים מנשק יכול להרחיב יותר ממנשק אחד שירותים במנשק הם תמיד מופשטים וציבוריים public interface MyInterface { public abstract int foo1(int i); int foo2(int i); The modifiers

More information

מערכים שעור מס. 4 כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1

מערכים שעור מס. 4 כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1 מערכים שעור מס. 4 דרור טובי דר' כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1 למה מערכים? ברצוננו לאחסן בתוכנית ציוני בחינה כדי לחשב את ממוצע הציונים וסטיית התקן. נניח ש 30 סטודנטים לקחו

More information

לתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions

לתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions מבוא לתיכנות עם MATLAB 234127 Lecture 5: Boolean logic and Boolean expressions Written by Prof. Reuven Bar-Yehuda, Technion 2013 Based on slides of Dr. Eran Eden, Weizmann 2008 1 >>g = [89 91 80 98]; >>p

More information

הנכות 1 םוכיס לוגרת 13 1

הנכות 1 םוכיס לוגרת 13 1 תוכנה 1 סיכום תרגול 13 1 קצת על מנשקים מנשק יכול להרחיב יותר ממנשק אחד שירותים במנשק הם תמיד מופשטים וציבוריים public interface MyInterface { public abstract int foo1(int i); int foo2(int i); The modifiers

More information

תוכנה 1. תרגול מספר 11: Static vs. Dynamic Binding מחלקות מקוננות Nested Classes

תוכנה 1. תרגול מספר 11: Static vs. Dynamic Binding מחלקות מקוננות Nested Classes תוכנה 1 תרגול מספר 11: Static vs. Dynamic Binding מחלקות מקוננות Nested Classes class Outer { static class NestedButNotInner {... class Inner {... מחלקות מקוננות NESTED CLASSES 2 מחלקה מקוננת Class) )Nested

More information

לתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions

לתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions מבוא לתיכנות עם MATLAB 23427 Lecture 5: Boolean logic and Boolean expressions Written by Prof. Reuven Bar-Yehuda, Technion 203 Based on slides of Dr. Eran Eden, Weizmann 2008 ביטויים לוגיים דוגמא: תקינות

More information

מבוא לתכנות ב- JAVA תרגול 7

מבוא לתכנות ב- JAVA תרגול 7 מבוא לתכנות ב- JAVA תרגול 7 רקורסיה - הקדמה הגדרה רקורסיבית: חדר הוא מסודר אם צד שמאל שלו מסודר שלו מסודר. וצד ימין שיטת פתרון רקורסיבית: פתרון מופעים פשוטים יותר של בעיה בכדי לפתור את הבעיה המקורית רקורסיה

More information

הנכות 1 םוכיס לוגרת 13 1

הנכות 1 םוכיס לוגרת 13 1 תוכנה 1 סיכום תרגול 13 1 בחינה באופק! הבחינה תכלול את כל הנושאים שכיסינו במהלך הסמסטר: כל ההרצאות כל תרגולים כל תרגילי בית חומר סגור שאלות אמריקאיות 2 קצת על מנשקים מנשק יכול להרחיב שירותים במנשק הם תמיד

More information

תזכורת: עץבינארי מבוא למדעי המחשב הרצאה 24: עצי חיפוש בינאריים

תזכורת: עץבינארי מבוא למדעי המחשב הרצאה 24: עצי חיפוש בינאריים מבוא למדעי המחשב הרצאה 2: עצי חיפוש בינאריים תזכורת: עץבינארי בנוסףלרשימהמקושרת ומערך, הצגנומבנהנתונים קונקרטיחדש עץבינארי עץבינארימורכבמ: שורש תת-עץשמאלי תת-עץימני A B C D E F G 2 תזכורת: שורש ותתי-עצים

More information

הקלחמ ה תמרב ת ונ וכ ת (static members ) יליזרב דהוא Java תפשב ם דקת מ תונכת ביבא ל ת תטיסרבינוא

הקלחמ ה תמרב ת ונ וכ ת (static members ) יליזרב דהוא Java תפשב ם דקת מ תונכת ביבא ל ת תטיסרבינוא ת כו נו ת ברמת ה מחלקה (static members) אוהד ברזילי תכנות מ תקד ם בשפת Java אוניברסיטת ת ל אביב static keyword שדות המוגדרים כ static מציינים כי הם מוגדרים ברמת המחלקה ולא ברמת עצם כל העצמים של אותה מחלקה

More information

Practical Session - Heap

Practical Session - Heap Practical Session - Heap Heap Heap Maximum-Heap Minimum-Heap Heap-Array A binary heap can be considered as a complete binary tree, (the last level is full from the left to a certain point). For each node

More information

Data Types. 9. Types. a collection of values and the definition of one or more operations that can be performed on those values

Data Types. 9. Types. a collection of values and the definition of one or more operations that can be performed on those values Data Types 1 data type: a collection of values and the definition of one or more operations that can be performed on those values C++ includes a variety of built-in or base data types: short, int, long,

More information

Java Programming Language Mr.Rungrote Phonkam

Java Programming Language Mr.Rungrote Phonkam 5 Java Programming Language Mr.Rungrote Phonkam rungrote@it.kmitl.ac.th Contents 1. Expressions 2. Control Flow 2.1 Condition 2.2 Multiple Branch 2.3 Lopps 2.4 Jump ก ก 1. Expressions ก ก ก ก ก 5/b%2+10;

More information

COMP-202: Foundations of Programming. Lecture 13: Recursion Sandeep Manjanna, Summer 2015

COMP-202: Foundations of Programming. Lecture 13: Recursion Sandeep Manjanna, Summer 2015 COMP-202: Foundations of Programming Lecture 13: Recursion Sandeep Manjanna, Summer 2015 Announcements Final exams : 26 th of June (2pm to 5pm) @ MAASS 112 Assignment 4 is posted and Due on 29 th of June

More information

תור שימושים בעולם התוכנה

תור שימושים בעולם התוכנה מבוא למדעי המחשב הרצאה : Queue, Iterator & Iterable תור מבנה נתונים אבסטרקטי תור שימושים בעולם התוכנה השימושים של תורים בעולם התוכנה מזכירים מאוד תורים במציאות: )VoIP( )YouTube( מקלדת שידור סרט באינטרנט

More information

תוכנה 1 * לא בהכרח בסדר הזה

תוכנה 1 * לא בהכרח בסדר הזה תוכנה 1 תרגול 7: מנשקים, פולימורפיזם ועוד * לא בהכרח בסדר הזה 2 מנשקים מנשקים מנשק )interface( הוא מבנה תחבירי ב- Java המאפשר לחסוך בקוד לקוח. מנשק מכיל כותרות של מתודות המימוש שלהן. )חתימות( ללא קוד אשר

More information

היצביט ומ - ןוכית ת וי נבת

היצביט ומ - ןוכית ת וי נבת תבני ו ת תיכון Patterns) (Design תבנ יו ת תיכון - מו טיבציה בחיי היום יום אנחנו מתארים דברים תוך שימוש בתבניות חוזרות: "מכונית א' היא כמו מכונית ב', אבל יש לה 2 דלתות במקום 4" "אני רוצה ארון כמו זה, אבל

More information

לתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions

לתיכנות עם MATLAB Lecture 5: Boolean logic and Boolean expressions מבוא לתיכנות עם MATLAB 234127 Lecture 5: Boolean logic and Boolean expressions Written by Prof. Reuven Bar-Yehuda, Technion 2013 Based on slides of Dr. Eran Eden, Weizmann 2008 1 motivation Proper academic

More information

Recursion Enums. Basics of Programming 1. Department of Networked Systems and Services G. Horváth, A.B. Nagy, Z. Zsóka, P. Fiala, A.

Recursion Enums. Basics of Programming 1. Department of Networked Systems and Services G. Horváth, A.B. Nagy, Z. Zsóka, P. Fiala, A. Recursion The enumerated type Recursion Enums Basics of Programming 1 Department of Networked Systems and Services G. Horváth, A.B. Nagy, Z. Zsóka, P. Fiala, A. Vitéz 31 October, 2018 based on slides by

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

משתנים שעור מס. 2 כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1

משתנים שעור מס. 2 כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1 משתנים שעור מס. 2 דרור טובי דר' כל הזכויות שמורות דר ' דרור טובי המרכז האוניברסיטאי אריאל 1 תפקיד המשתנים הצהרה על משתנה השמת ערך במשתנה int a, b, c; a = 1234; b = 99; c = a + b; משתנים מאפשרים לנו לשמור

More information

CSE 341 Section Handout #6 Cheat Sheet

CSE 341 Section Handout #6 Cheat Sheet Cheat Sheet Types numbers: integers (3, 802), reals (3.4), rationals (3/4), complex (2+3.4i) symbols: x, y, hello, r2d2 booleans: #t, #f strings: "hello", "how are you?" lists: (list 3 4 5) (list 98.5

More information

הנכות 1 םוכיס לוגרת 13 1

הנכות 1 םוכיס לוגרת 13 1 תוכנה 1 סיכום תרגול 13 1 בחינה באופק! הבחינה תכלול את כל הנושאים שכיסינו במהלך הסמסטר: כל ההרצאות כל תרגולים כל תרגילי בית חומר סגור שאלות אמריקאיות 2 קצת על מנשקים מנשק יכול להרחיב יותר ממנשק אחד שירותים

More information

תוכנה 1 * לא בהכרח בסדר הזה

תוכנה 1 * לא בהכרח בסדר הזה תוכנה 1 תרגול 7: מנשקים, פולימורפיזם ועוד * לא בהכרח בסדר הזה 2 מנשקים מנשקים - תזכורת מנשק )interface( הוא מבנה תחבירי ב- Java המאפשר לחסוך בקוד לקוח. מנשק מכיל כותרות של מתודות )חתימות(. מימוש דיפולטיבי

More information

תכנות מונחה עצמים משחקים תשע"ו

תכנות מונחה עצמים משחקים תשעו move semantics 1 תכנות מונחה עצמים ופיתוח משחקים תשע"ו סמנטיקת ההעברה semantics( )Move move semantics 2 מטרה האצה של התוכניות, שיפור בביצועים על ידי חסכון בבנייה והעתקה של אובייקטים זמניים move semantics

More information

CMIS 102 Hands-On Lab

CMIS 102 Hands-On Lab CMIS 10 Hands-On Lab Week 8 Overview This hands-on lab allows you to follow and experiment with the critical steps of developing a program including the program description, analysis, test plan, and implementation

More information

CS Programming I: Arrays

CS Programming I: Arrays CS 200 - Programming I: Arrays Marc Renault Department of Computer Sciences University of Wisconsin Madison Fall 2017 TopHat Sec 3 (PM) Join Code: 719946 TopHat Sec 4 (AM) Join Code: 891624 Array Basics

More information

Syntax and Variables

Syntax and Variables Syntax and Variables What the Compiler needs to understand your program, and managing data 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line

More information

Advanced Computer Programming

Advanced Computer Programming Hazırlayan Yard. Doç. Dr. Mehmet Fidan ARRAYS A group of data with same type stored under one variable. It is assumed that elements in that group are ordered in series. In C# language arrays are has System.Array

More information

Notes - Recursion. A geeky definition of recursion is as follows: Recursion see Recursion.

Notes - Recursion. A geeky definition of recursion is as follows: Recursion see Recursion. Notes - Recursion So far we have only learned how to solve problems iteratively using loops. We will now learn how to solve problems recursively by having a method call itself. A geeky definition of recursion

More information

High Performance Computing

High Performance Computing High Performance Computing MPI and C-Language Seminars 2009 Photo Credit: NOAA (IBM Hardware) High Performance Computing - Seminar Plan Seminar Plan for Weeks 1-5 Week 1 - Introduction, Data Types, Control

More information

Arrays III and Enumerated Types

Arrays III and Enumerated Types Lecture 15 Arrays III and Enumerated Types Multidimensional Arrays & enums CptS 121 Summer 2016 Armen Abnousi Multidimensional Arrays So far we have worked with arrays with one dimension. Single dimensional

More information

34. Recursion. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

34. Recursion. Java. Summer 2008 Instructor: Dr. Masoud Yaghini 34. Recursion Java Summer 2008 Instructor: Dr. Masoud Yaghini Outline Introduction Example: Factorials Example: Fibonacci Numbers Recursion vs. Iteration References Introduction Introduction Recursion

More information

Answers to review questions from Chapter 2

Answers to review questions from Chapter 2 Answers to review questions from Chapter 2 1. Explain in your own words the difference between a method and a program. A method computes a value or performs some operation on behalf of the code for a program.

More information

Scientific Programming in C X. More features & Fortran interface

Scientific Programming in C X. More features & Fortran interface Scientific Programming in C X. More features & Fortran interface Susi Lehtola 20 November 2012 typedef typedefs are a way to make shorthand for data types, and possibly also make the code more general

More information

Practical Session No. 14 Topological sort,amortized Analysis

Practical Session No. 14 Topological sort,amortized Analysis Practical Session No. 14 Topological sort,amortized Analysis Topological- Sort Topological sort Ordering of vertices in a directed acyclic graph (DAG) G=(V,E) such that if there is a path from v to u in

More information

מבוא למדעי המחשב תרגול 8 רשימה משורשרת כללית, Comparator

מבוא למדעי המחשב תרגול 8 רשימה משורשרת כללית, Comparator מבוא למדעי המחשב 2017 תרגול 8 רשימה משורשרת כללית, Comparator בתרגול היום. LinkedList בניית ההכללה מ- LinkIntList תרגול המבנה ושימושיו ממשקים: Comparator Sorted Linked List ל- LinkedList ע"י שימוש ב- Comparator

More information

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below. C212 Early Evaluation Exam Mon Feb 10 2014 Name: Please provide brief (common sense) justifications with your answers below. 1. What is the type (and value) of this expression: 5 * (7 + 4 / 2) 2. What

More information

מחרוזות ב Java ותכנות מונחה בדיקות )Test Driven Development(

מחרוזות ב Java ותכנות מונחה בדיקות )Test Driven Development( מחרוזות ב Java ותכנות מונחה בדיקות )Test Driven Development( תוכנה 1 תרגול 8 String Immutability Strings are constants String s = " Tea "; s = s.trim(); s = s.replace('t', 'S'); s 1 2 3 " Tea " "Tea" "Sea"

More information

i.e.: n! = n (n 1)

i.e.: n! = n (n 1) Recursion and Java Recursion is an extremely powerful problemsolving technique. Problems that at first appear difficult often have simple recursive solutions. Recursion breaks a problems into several smaller

More information

Recursion CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2011

Recursion CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2011 Recursion CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2011 Recursion A method calling itself Overview A new way of thinking about a problem Divide and conquer A powerful programming

More information

II. Compiling and launching from Command-Line, IDE A simple JAVA program

II. Compiling and launching from Command-Line, IDE A simple JAVA program Contents Topic 01 - Java Fundamentals I. Introducing JAVA II. Compiling and launching from Command-Line, IDE A simple JAVA program III. How does JAVA work IV. Review - Programming Style, Documentation,

More information

COS 126 Midterm 1 Written Exam Fall 2011

COS 126 Midterm 1 Written Exam Fall 2011 NAME: login id: Precept: COS 126 Midterm 1 Written Exam Fall 2011 This test has 8 questions, weighted as indicated. The exam is closed book, except that you are allowed to use a one page cheatsheet. No

More information

Wentworth Institute of Technology COMP1050 Computer Science II Spring 2017 Derbinsky. Recursion. Lecture 13. Recursion

Wentworth Institute of Technology COMP1050 Computer Science II Spring 2017 Derbinsky. Recursion. Lecture 13. Recursion Lecture 13 1 What is? A method of programming in which a method refers to itself in order to solve a problem Never necessary In some situations, results in simpler and/or easier-to-write code Can often

More information

ASP.Net Web API.

ASP.Net Web API. ASP.Net Web API 1 מה זה? Web API View בלבד ולא Data אותו מממש השרת והוא מחזיר לקליינט API הוא Web API הבקשה והתשובה הן בפרוטוקול Http\Https הקליינטים של Web API יכולים להיות רבים : אפשר להשתמש גם בMVC

More information

תוכנה 1 תרגול מספר 13

תוכנה 1 תרגול מספר 13 1 תוכנה 1 תרגול מספר 13 ו- HashCode Equals עוד על טיפוסים מוכללים )Advanced Generics( חריגים )Exceptions( בית הספר למדעי המחשב אוניברסיטת תל אביב 1 2 ו- HASHCODE EQUALS 3 תזכורת: המחלקה Object package

More information

תוכנה 1 תרגול מספר 13

תוכנה 1 תרגול מספר 13 1 2 תוכנה 1 תרגול מספר 13 ו- HashCode Equals עוד על טיפוסים מוכללים )Advanced Generics( ו- HASHCODE EQUALS חריגים )Exceptions( בית הספר למדעי המחשב אוניברסיטת תל אביב 1 3 4 package java.lang; תזכורת: המחלקה

More information

What you learned so far. Loops & Arrays efficiency for statements while statements. Assignment Plan. Required Reading. Objective 2/3/2018

What you learned so far. Loops & Arrays efficiency for statements while statements. Assignment Plan. Required Reading. Objective 2/3/2018 Loops & Arrays efficiency for statements while statements Hye-Chung Kum Population Informatics Research Group http://pinformatics.org/ License: Data Science in the Health Domain by Hye-Chung Kum is licensed

More information

CS1 Recitation. Week 2

CS1 Recitation. Week 2 CS1 Recitation Week 2 Sum of Squares Write a function that takes an integer n n must be at least 0 Function returns the sum of the square of each value between 0 and n, inclusive Code: (define (square

More information

Recursion. Overview. Mathematical induction. Hello recursion. Recursion. Example applications. Goal: Compute factorial N! = 1 * 2 * 3...

Recursion. Overview. Mathematical induction. Hello recursion. Recursion. Example applications. Goal: Compute factorial N! = 1 * 2 * 3... Recursion Recursion Overview A method calling itself A new way of thinking about a problem Divide and conquer A powerful programming paradigm Related to mathematical induction Example applications Factorial

More information

News and information! Review: Java Programs! Feedback after Lecture 2! Dead-lines for the first two lab assignment have been posted.!

News and information! Review: Java Programs! Feedback after Lecture 2! Dead-lines for the first two lab assignment have been posted.! True object-oriented programming: Dynamic Objects Reference Variables D0010E Object-Oriented Programming and Design Lecture 3 Static Object-Oriented Programming UML" knows-about Eckel: 30-31, 41-46, 107-111,

More information

מבוא לתכנות תוכנית שעור מס. 1 1 דר' דרור טובי, המרכז האוניברסיטאי אריאל בשומרון.

מבוא לתכנות תוכנית שעור מס. 1 1 דר' דרור טובי, המרכז האוניברסיטאי אריאל בשומרון. מבוא לתכנות תוכנית ראשונה שעור מס. 1 דרור טובי דר' 1 מבוא לתכנות בשפת ++C C \ שלום!! מרצה ד"ר דרור טובי, drorto@ariel.ac.il שעות קבלה: יום ב, 10-12 טלפון )אריאל( 03 9076547 אתר הקורס: http://www.ariel.ac.il/cs/pf/tdror/courses/cpp

More information

Definition: Data Type A data type is a collection of values and the definition of one or more operations on those values.

Definition: Data Type A data type is a collection of values and the definition of one or more operations on those values. Data Types 1 Definition: Data Type A data type is a collection of values and the definition of one or more operations on those values. Base Data Types All the values of the type are ordered and atomic.

More information

מבוא לתכנות ב- JAVA מעבדה 3. Ipc161-lab3

מבוא לתכנות ב- JAVA מעבדה 3. Ipc161-lab3 מבוא לתכנות ב- JAVA מעבדה 3 Ipc161-lab3 נושאי התרגול ניפוי שגיאות לולאות בדיקת תרגילים בקורס )השוואת פלטים למול הפתרון המצופה( כיצד להפנות את פלט התוכנית לקובץ טקסט איך להשוות תכנים של שני קבצים בעזרת

More information

Lecture 6. Drinking. Nested if. Nested if s reprise. The boolean data type. More complex selection statements: switch. Examples.

Lecture 6. Drinking. Nested if. Nested if s reprise. The boolean data type. More complex selection statements: switch. Examples. // Simple program to show how an if- statement works. import java.io.*; Lecture 6 class If { static BufferedReader keyboard = new BufferedReader ( new InputStreamReader( System.in)); public static void

More information

מצליחה. 1. int fork-bomb() 2. { 3. fork(); 4. fork() && fork() fork(); 5. fork(); printf("bla\n"); 8. return 0; 9. }

מצליחה. 1. int fork-bomb() 2. { 3. fork(); 4. fork() && fork() fork(); 5. fork(); printf(bla\n); 8. return 0; 9. } שאלה : (4 נקודות) א. ב. ג. (5 נקודות) הגדירו את המונח race-condition במדוייק לא להשמיט פרטים. ספקו דוגמא. (5 נקודות) מהו? Monitor נא לספק הגדרה מלאה. ( נקודות) ( נקודות) ציינו כמה תהליכים יווצרו בקוד הבא

More information

תרשים המחלקות ותרשים העצמים

תרשים המחלקות ותרשים העצמים 1 תרשים המחלקות ותרשים העצמים חלק שלישי: ניתוח ועיצוב מערכות מידע באמצעות שימוש ב- UML ומתודולוגיית ה- Process )UP( Unified E1 3 E2 2 Outline UML Introduction Class Diagram Class Association Self association

More information

Programming for Engineers in Python

Programming for Engineers in Python Programming for Engineers in Python Lecture 9: Sorting, Searching and Time Complexity Analysis Autumn 2011-12 1 Lecture 8: Highlights Design a recursive algorithm by 1. Solving big instances using the

More information

Programming for Engineers in Python

Programming for Engineers in Python Programming for Engineers in Python Lecture 9: Sorting, Searching and Time Complexity Analysis Autumn 2011-12 1 Lecture 8: Highlights Design a recursive algorithm by 1. Solving big instances using the

More information

More Binary Search Trees AVL Trees. CS300 Data Structures (Fall 2013)

More Binary Search Trees AVL Trees. CS300 Data Structures (Fall 2013) More Binary Search Trees AVL Trees bstdelete if (key not found) return else if (either subtree is empty) { delete the node replacing the parents link with the ptr to the nonempty subtree or NULL if both

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Instructor training course schedule v3 Confirmed courses due completion by 31 st July 2019

Instructor training course schedule v3 Confirmed courses due completion by 31 st July 2019 Confirmed courses due completion by 31 st July 2019 Courses: 2 Orientation 2 IoT Fundamentals 2 Networking Essentials 2 Cybersecurity Essentials 2 IT Essentials: PC Hardware and Software 2 CCNA Routing

More information

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs. Java SE11 Development Java is the most widely-used development language in the world today. It allows programmers to create objects that can interact with other objects to solve a problem. Explore Java

More information

More BSTs & AVL Trees bstdelete

More BSTs & AVL Trees bstdelete More BSTs & AVL Trees bstdelete if (key not found) return else if (either subtree is empty) { delete the node replacing the parents link with the ptr to the nonempty subtree or NULL if both subtrees are

More information

Arrays. Arrays. Wolfgang Schreiner Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria

Arrays. Arrays. Wolfgang Schreiner Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria Arrays Wolfgang Schreiner Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria Wolfgang.Schreiner@risc.jku.at http://www.risc.jku.at Wolfgang Schreiner RISC Arrays

More information

תרגול 3 מערכים ופונקציות

תרגול 3 מערכים ופונקציות מבוא למדעי המחשב 2017 תרגול 3 מערכים ופונקציות מערכים מאפשרים עבודה עם מקבצים של נתונים פונקציות מאפשרות אבסטרקציה והאחדה של הקוד ראינו בהרצאה מערכים הצהרה, אתחול, גישה לאיברים במערך יצוג בזיכרון ובטבלת

More information

ECSE 321 Assignment 2

ECSE 321 Assignment 2 ECSE 321 Assignment 2 Instructions: This assignment is worth a total of 40 marks. The assignment is due by noon (12pm) on Friday, April 5th 2013. The preferred method of submission is to submit a written

More information

Exam 2 ITEC 120 Principles of Computer Science I Spring: 2017

Exam 2 ITEC 120 Principles of Computer Science I Spring: 2017 Exam 2 ITEC 120 Principles of Computer Science I Spring: 2017 I will abide by the Radford University Honor Code. Name Signature On this exam, you may NOT use already written methods such as Character class

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science Department Lecture 3: C# language basics Lecture Contents 2 C# basics Conditions Loops Methods Arrays Dr. Amal Khalifa, Spr 2015 3 Conditions and

More information

Array. Array Declaration:

Array. Array Declaration: Array Arrays are continuous memory locations having fixed size. Where we require storing multiple data elements under single name, there we can use arrays. Arrays are homogenous in nature. It means and

More information

Purpose of the Simulated function

Purpose of the Simulated function How to replace recursive functions using stack a http://www.codeproject.com/articles/418776/how 10,661,731 members (57,717 online) a20121248 251 Sign out home articles quick answers discussions features

More information

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue General Loops in Java Look at other loop constructions Very common while loop: do a loop a fixed number of times (MAX in the example) int

More information

1. Introduction to Java for JAS

1. Introduction to Java for JAS Introduction to Java and Agent-Based Economic Platforms (CF-904) 1. Introduction to Java for JAS Mr. Simone Giansante Email: sgians@essex.ac.uk Web: http://privatewww.essex.ac.uk/~sgians/ Office: 3A.531

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College October 11, 2017 Outline Outline 1 Chapter 6: Recursion Outline Chapter 6: Recursion 1 Chapter 6: Recursion Measuring Complexity

More information

All King County Summary Report

All King County Summary Report September, 2016 MTD MARKET UPDATE Data Current Through: September, 2016 18,000 16,000 14,000 12,000 10,000 8,000 6,000 4,000 2,000 0 Active, Pending, & Months Supply of Inventory 15,438 14,537 6.6 6.7

More information

Arrays. CSE 142, Summer 2002 Computer Programming 1.

Arrays. CSE 142, Summer 2002 Computer Programming 1. Arrays CSE 142, Summer 2002 Computer Programming 1 http://www.cs.washington.edu/education/courses/142/02su/ 5-Aug-2002 cse142-16-arrays 2002 University of Washington 1 Reading Readings and References»

More information

תוכנה 1 מבני נתונים גנריים

תוכנה 1 מבני נתונים גנריים תוכנה 1 מבני נתונים גנריים תרגול 8 Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework Interfaces Implementations Algorithms 2 Online Resources

More information

Recursion. Fundamentals of Computer Science

Recursion. Fundamentals of Computer Science Recursion Fundamentals of Computer Science Outline Recursion A method calling itself All good recursion must come to an end A powerful tool in computer science Allows writing elegant and easy to understand

More information

recursive algorithms 1

recursive algorithms 1 COMP 250 Lecture 11 recursive algorithms 1 Oct. 2, 2017 1 Example 1: Factorial (iterative)! = 1 2 3 1 factorial( n ){ // assume n >= 1 result = 1 for (k = 2; k

More information

Recursive Definitions

Recursive Definitions Recursion Objectives Explain the underlying concepts of recursion Examine recursive methods and unravel their processing steps Explain when recursion should and should not be used Demonstrate the use of

More information

מבוא לתכנות ב- JAVA תרגול 6

מבוא לתכנות ב- JAVA תרגול 6 מבוא לתכנות ב- JAVA תרגול 6 מה בתרגול )methods( פונקציות/שיטות ב- Java הגדרת פונקציה קריאה/הפעלה העברת ארגומנטים ערכי החזרה מבוא לפונקציות- שימוש חוזר בקוד נניח שבמהלך תוכנית נדרשתם לחשב את הסכום של המספרים

More information

סכום (סדרת ערכים) אחרת - דוגמא: סכום-ספרות (num) אם < 10 num החזר 1 או אם = 0 = num החזר 0 public static int numofdigits (int num)

סכום (סדרת ערכים) אחרת - דוגמא: סכום-ספרות (num) אם < 10 num החזר 1 או אם = 0 = num החזר 0 public static int numofdigits (int num) 1 תבנית צבירה תבניות אלגוריתמיות לפעולות רקורסיביות תבנית צבירה לסדרת ערכים: סכום (סדרת ערכים) החזר את ערך הקצה + סכום (סדרת הערכים ללא ערך הקצה) דוגמא: פעולה המחזירה את סכום הספרות שבמספר שלם לא שלילי

More information

Java Bytecode (binary file)

Java Bytecode (binary file) Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.

More information

מבוא לתכנות ב- JAVA תרגול 5. Ipc161- practical session 5

מבוא לתכנות ב- JAVA תרגול 5. Ipc161- practical session 5 מבוא לתכנות ב- JAVA תרגול 5 Ipc161- practical session 5 מה בתרגול מערכים דו ממדיים )methods( פונקציות/שיטות ב- Java הגדרת פונקציה קריאה/הפעלה העברת ארגומנטים ערכי החזרה מערך דו ממדי מערך של מערכים חד ממדיים

More information

PROGRAMMING FUNDAMENTALS

PROGRAMMING FUNDAMENTALS PROGRAMMING FUNDAMENTALS Q1. Name any two Object Oriented Programming languages? Q2. Why is java called a platform independent language? Q3. Elaborate the java Compilation process. Q4. Why do we write

More information

This report is based on sampled data. Jun 1 Jul 6 Aug 10 Sep 14 Oct 19 Nov 23 Dec 28 Feb 1 Mar 8 Apr 12 May 17 Ju

This report is based on sampled data. Jun 1 Jul 6 Aug 10 Sep 14 Oct 19 Nov 23 Dec 28 Feb 1 Mar 8 Apr 12 May 17 Ju 0 - Total Traffic Content View Query This report is based on sampled data. Jun 1, 2009 - Jun 25, 2010 Comparing to: Site 300 Unique Pageviews 300 150 150 0 0 Jun 1 Jul 6 Aug 10 Sep 14 Oct 19 Nov 23 Dec

More information

Seattle (NWMLS Areas: 140, 380, 385, 390, 700, 701, 705, 710) Summary

Seattle (NWMLS Areas: 140, 380, 385, 390, 700, 701, 705, 710) Summary September, 2016 MTD MARKET UPDATE Data Current Through: September, 2016 (NWMLS Areas: 140, 380, 385, 390,, 701, 705, 710) Summary Active, Pending, & Months Supply of Inventory 5,000 4,500 4,000 3,500 4,091

More information

Question: Total Points: Score:

Question: Total Points: Score: CS 170 Exam 2 Section 001 Fall 2014 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

Recursion. General Algorithm for Recursion. When to use and not use Recursion. Recursion Removal. Examples

Recursion. General Algorithm for Recursion. When to use and not use Recursion. Recursion Removal. Examples Recursion General Algorithm for Recursion When to use and not use Recursion Recursion Removal Examples Comparison of the Iterative and Recursive Solutions Exercises Unit 19 1 General Algorithm for Recursion

More information

Computer Programming, I. Laboratory Manual. Final Exam Solution

Computer Programming, I. Laboratory Manual. Final Exam Solution Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Final Exam Solution

More information